package com.bltec.emergency.mapper;

import com.bltec.emergency.model.RecordExercise;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RecordExerciseMapper {

    //插入一条exercise记录
    @Insert("insert into record_exercise (exercise_time,exercise_requirement,exercise_position,exercise_name,exercise_content,exercise_unit,create_by,create_time,enable) " +
            "values(#{exerciseTime},#{exerciseRequirement},#{exercisePosition},#{exerciseName},#{exerciseContent},#{exerciseUnit},#{createBy},#{createTime},#{enable})")
    boolean insert(RecordExercise recordExercise);

    //通过exerciseName字段删除exercise记录
    @Delete("delete from record_exercise where exercise_name=#{exerciseName}")
    boolean deleteByExerciseName(String exerciseName);

    //通过id设置一条记录为不可用
    @Update("update record_exercise set enable=0 where id=#{id}")
    boolean setDisableById(Long id);

    //通过id更新一条记录
    @Update("update record_exercise set exercise_time=#{exerciseTime},exercise_requirement=#{exerciseRequirement}," +
            "exercise_position=#{exercisePosition},exercise_name=#{exerciseName},exercise_content=#{exerciseContent}," +
            "exercise_unit=#{exerciseUnit},update_by=#{updateBy},update_time=#{updateTime} where id=#{id}")
    boolean updateExerciseById(RecordExercise recordExercise);

    //查找符合exerciseName字段的记录
    @Select("select * from record_exercise where exercise_name =#{exerciseName} and enable=1")
    RecordExercise getExerciseByExerciseName(String exerciseName);

    //查找符合exerciseName字段的记录的id
    @Select("select id from record_exercise where exercise_name =#{exerciseName} and enable=1")
    Long getIdByExerciseName(String exerciseName);

    //查找符合id字段的记录
    @Select("select * from record_exercise where id =#{id} and enable=1")
    RecordExercise getExerciseById(Long id);

    //查找所有记录
    @Select("select * from record_exercise where enable=1")
    List<RecordExercise> selectAll();
}